package com.sky.controller;

import com.sky.dto.es.ProductModel;
import com.sky.exception.BizCodeEnum;
import com.sky.service.ProductSearchService;
import com.sky.utils.R;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/productSearch")
public class ProductSearchController {

    @Resource
    private ProductSearchService productSearchService;

    @PostMapping("/addProductSkuInfo")
    public R addProductSkuInfo(@RequestBody List<ProductModel> productModels){
        try {
            boolean flag = productSearchService.addProductSkuInfo(productModels);
            return flag ? R.ok() : R.error(BizCodeEnum.PRODUCT_UP_EXCEPTION.getCode(), BizCodeEnum.PRODUCT_UP_EXCEPTION.getMsg());
        } catch (IOException e) {
            return R.error(BizCodeEnum.PRODUCT_UP_EXCEPTION.getCode(), BizCodeEnum.PRODUCT_UP_EXCEPTION.getMsg());
        }
    }
}
